<%@include file="startUpIncludes.jsp" %>
   <%--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> --%> 
  <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
        <title>
            Leads
        </title>
        <script type="text/javascript" src="../js/jquery1-8.js"></script>
<script type="text/javascript" src="../js/jquery-ui-core.js"></script>
<script type="text/javascript" src="../js/jquery-ui-widget.js"></script>
	 <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="../js/modalwin.js">
    
    </script>
        <script type="text/javascript">
    $(document).ready (function () {
    	$('.delete').click (function () {
    		return confirm ("Are you sure you want to " + $(this).attr ("title") + "?") ;
    	}) ; 
    }) ;
</script>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["searchForm"]["query"].value;
if (x==null || x=="")
  {
  alert("You Must Input your search");
  return false;
  }
else
    return true;
}
function counterChange()
{
	var a=document.getElementById("counter").value;
	window.location =  "/sales/s/leads?count="+a;
}
</script>
<style>
div.scroll
{
width: 1000px;
  height: 1000px;
  overflow: auto;
}
</style>
    </head>
    <body class="leadsPage">
    <jsp:include page="header.jsp" >
		<jsp:param value="true" name="loggedIn"/>
	</jsp:include>
	<div class="modal-win-bg">
        <div class="modal-win-box">
            <div class="modal-win-hd">
                <span class="modal-win-title"></span>
                <span class="modal-win-close">x</span>
            </div>
            <div class="modal-win-content"></div>
            <a class="form-btn modal-win-start">Delete</a>
            <a class="form-btn modal-win-ok">Cancel</a>
        </div>
    </div>
    <div class="wrap">
	<div class="fitBG">
        <div class="main">
		<%@include file="basicLeftMenu.jsp" %>
            <div class="content">
				<jsp:include page="tabs.jsp" >
					<jsp:param value="leads" name="currentPage"/>
				</jsp:include>
                <div class="tab-content">
                <h3>Leads</h3>
                 <form name="searchForm" action="/sales/s/search" method="post" class="search-form"  onsubmit="return validateForm();">                	
				<input type="text" name="query" class="TB" value="${query}"/>
                	<input type="submit" value="search" class="inf"/>
                </form>
				<div class="lead-view">
				<%-- <form name="leadView" action="/sales/s/view">
				<span>View lead using: </span>
				<select class="TB" name="viewId">
                <c:forEach items="${ leadViews }" var="leadView">
					<option value="${ leadView.id }">${ leadView.name }</option>
				</c:forEach>
				</select>
				<input type="hidden" value="1" name="leadTypeId"/>
				<input type="submit" value="GO" class="inf"/>
				</form>
				<a href="#">Edit Selected View</a>
				<a href="#">Create New View</a> --%>
				</div>
                <div class="content-block">
                    <h4>Recent Leads</h4>
                    <div class="action-btns">
                    		<shiro:hasRole name="leadAdd">
                    		<a href="newLead" class="form-btn">New Lead</a>
                    		</shiro:hasRole>
							<shiro:hasRole name="leadImport">
                    		<a href="importLeads" class="form-btn">Import Leads</a>
                    		</shiro:hasRole>  
                    </div>
	                <c:choose>
	                <c:when test="${empty leads}">
	                <div class="noData">No data to preview...</div>
	                </c:when>
	                <c:otherwise>
                    <div class="scroll-table">
                    <table class="recent-leads">
                        <thead>
                            <tr>
                                <th class="p40">Action</th>
                                <th class="p15">Name</th>
                                <th class="p15">Company</th>
                                <th class="p15">Lead Status</th>
                                <th class="p15">Lead Owner</th>
                            </tr>
                        </thead>
                        <tbody>
    					<c:forEach items="${leads}" var="lead">
<%--     						<c:if test="${lead.isConverted==false}"> --%>
                            <tr class="even">
                                <td>
                                <shiro:hasRole name="leadView">
                                <a href="viewLead.html?id=${lead.id}">View</a>
                                </shiro:hasRole>
                                <shiro:hasRole name="leadEdit"> <a href="editLead.html?id=${lead.id}">Edit</a></shiro:hasRole>                   
	                                <%--added by hisham --%>
	                                <script type="text/javascript">
									    var tID = '${lead.id}';
									</script>
	                                <shiro:hasRole name="leadDelete">
	                                <a href="deleteLead.html?id=${lead.id}" title="Delete the selected Lead" class="delete">Delete</a>
<!-- 	                                 <a class="fire-modal-win delete-lead">Delete</a> -->
	                                </shiro:hasRole>
	                                <shiro:hasRole name="leadConvert">
	                                <c:choose>
	                                <c:when test="${lead.isConverted == true }">
	                                	<span>Converted|</span>
	                                </c:when>
	                                <c:otherwise>
	                                	<a href="/sales/s/convert-lead?id=${lead.id}">Convert</a>
	                                </c:otherwise>
                               	 	</c:choose>
                               	 	</shiro:hasRole>
                               	 	<shiro:hasRole name="callAdd">
                               	 	<a href="/sales/s/new-call?parentId=${lead.id}&parentType=lead">Add Call</a>
                               	 	</shiro:hasRole>
                               	 	<shiro:hasRole name="appointmentAdd">
                               	 	<a href="/sales/s/new-appointment?parentId=${lead.id}&parentType=lead">Add Appointment</a>
                               	 	</shiro:hasRole>
                     			<shiro:hasRole name="leadFellow">
                     			<c:choose>
	                                <c:when test="${lead.isFollowed == true }">
	                                	<img src="../images/icon-followed.png"/>
	                                </c:when>
	                                <c:otherwise>
	                                	<a href="/sales/s/followLead?leadId=${lead.id}"><img src="../images/icon-follow.png"/></a></td>
	                                </c:otherwise>
                                </c:choose>
                     			</shiro:hasRole>
                                <td>${lead.fName} ${lead.lName}</td>
                                <td>${lead.companyName}</td>
                                <c:choose>
			                       	<c:when test="${lead.leadStatus=='--none--'}">
			                       		<td>  </td>
			                       	</c:when>
			                       	<c:otherwise>
										<td>${lead.leadStatus}</td>                       		
			                       	</c:otherwise>	
		                       	</c:choose>
                                <td>${lead.leadOwner.fName}</td>
                            </tr>
<%--                             </c:if> --%>
                		</c:forEach>
                        </tbody>
                    </table>
                    </div>
                    </c:otherwise>
                    </c:choose>
                    <c:choose>
                    	<c:when test="${empty leads}">
                    	</c:when>
                    	<c:otherwise>
                    <c:choose>
                        	<c:when test="${index <=0 }">
                        		<span>first</span>
                        	</c:when>
                        	<c:otherwise>
                        		<a id ="first" href="/sales/s/leads?index=${0}&pages=${pages}&count=${count}">first</a>
                        	</c:otherwise>
                        </c:choose>
                    	<c:choose>
                        	<c:when test="${index <=0 }">
                        		<span>prev</span>
                        	</c:when>
                        	<c:otherwise>
                        		<a id ="prev" href="/sales/s/leads?index=${index-1}&pages=${pages}&count=${count}">prev</a>
                        	</c:otherwise>
                        </c:choose>
                        --${index+1}--
                        <c:choose>
                        	<c:when test="${index+1 >=pages }">
                        		<span>next</span>
                        	</c:when>
                        	<c:otherwise>
                        		<a id ="next" href="/sales/s/leads?index=${index+1}&pages=${pages}&count=${count}">next</a>
                        	</c:otherwise>
                        </c:choose>
                        <c:choose>
                        	<c:when test="${index+1 >=pages }">
                        		<span>last</span>
                        	</c:when>
                        	<c:otherwise>
                        		<a id ="last" href="/sales/s/leads?index=${pages-1}&pages=${pages}&count=${count}">last</a>
                        	</c:otherwise>
                        </c:choose>
                        
                        <select id ="counter" name="counter" onchange="counterChange();">
                        	<c:choose>
                        	<c:when test="${count==5}">
                        		<option value="5" selected="selected">5</option>
                        		<option value="10">10</option>
	                            <option value="15">15</option>
                        	</c:when>
                        	<c:when test="${count==10}">
                        		<option value="5">5</option>
	                        	<option value="10" selected="selected">10</option>
	                         	<option value="15">15</option>
                        	</c:when>
                        	<c:when test="${count==15}">
                        		<option value="5">5</option>
	                        	<option value="10">10</option>
	                         	<option value="15" selected="selected">15</option>
                        	</c:when>
                        	</c:choose>
                        </select>
                        </c:otherwise>
                    </c:choose>
                
                </div>
            </div>
        </div>
        
    <%@include file="footer.jspf" %>
    </div>
    </div>

    </body>
</html>